import Vue from 'vue'

export default {
	install: function (Vue) {

		// 防止重复提交
		Vue.directive('noMoreClick', {
			inserted(el, binding) {
				el.addEventListener('click', e => {
					let time = 3000
					let value = el.innerText
					if (Number(binding.arg) > 3000) {
						time = Number(binding.arg)
					}
					let countdown = time / 1000
					el.disabled = true
					// setTimeout(() => {
					// 	el.disabled = false
					// }, time)
					let timeLimit = setInterval(() => {
						countdown--
						// el.innerText = `${countdown} 秒后可重新点击`
						el.classList.add('BtnDisabled')
						if (countdown == 0) {
							// el.innerText = value
							el.disabled = false
							el.classList.remove("BtnDisabled");
							clearInterval(timeLimit)
						}
					}, 1000)
				})
			},
		})
	
	},
}
